package com.itbaizhan;

import com.SpringConfig;
import com.itbaizhan.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/*使用配置类  不使用配置文件（applicationContext.xml）*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)//读取配置类
public class AccountServiceTest2 {
    @Autowired
    private AccountService accountService;
    @Test
    public void test1(){
        accountService.transfer(1,2,100);
    }
    /* 没有配置dataSource 没有创建SqlSessionFactory对象与创建MapperScannerConfigurer对象
    之前都是在applicationContext中配置
    在配置类中配置这些，就不会报错
    Error creating bean with name 'accountService': Unsatisfied dependency expressed through
    field 'accountDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
    No qualifying bean of type 'com.itbaizhan.dao.AccountDao' available: expected at least 1 bean which qualifies as
    autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}*/
}
